{extend name="common/base"/}
<!-- 主体 -->
{block name="body"}
<form class="layui-form p-4">
	<h3 class="pb-3">参数配置</h3>
	<table class="layui-table layui-table-form">
        {volist name="config" id="vo"}
        {php}$kv = $key;{/php}
        {eq name="$vo.type" value="text"}
            <tr>
                <td class="layui-td-gray-2">{$vo.title}</td>
                <td>
                    <textarea placeholder="请输入{$vo.title}" name="{$key}" class="layui-textarea">{$vo.value}</textarea>
                    {notempty name="$vo.tips" }
                    <div class="layui-form-mid layui-text-em">{$vo.tips}</div>
                    {/notempty}
                </td>
            </tr>
        {/eq}
        {eq name="$vo.type" value="string"}
            <tr>
                <td class="layui-td-gray-2">{$vo.title}</td>
                <td class="layui-form-item">
                    <div class="layui-input-inline layui-input-wrap" style="width: 400px;">
                        <input type="text" name="{$key}" autocomplete="off" placeholder="请输入{$vo.title}" class="layui-input" value="{$vo.value}">
                    </div>
                    {notempty name="$vo.tips" }
                    <div class="layui-form-mid layui-text-em">{$vo.tips}</div>
                    {/notempty}
                </td>
            </tr>
        {/eq}
        {eq name="$vo.type" value="radio"}
            <tr>
                <td class="layui-td-gray-2">{$vo.title}</td>
                <td>
                    <div class="layui-form-item">
                        {volist name="vo.options" id="item" key="k"}
                            <input type="radio" name="{$kv}" value="{$key}" title="{$item}" {eq name="$key" value="$vo.value"}checked{/eq}>
                        {/volist}
                    </div>
                    {notempty name="$vo.tips" }
                    <div class="layui-form-mid layui-text-em">{$vo.tips}</div>
                    {/notempty}
                </td>
            </tr>
        {/eq}
        {eq name="$vo.type" value="checkbox"}
            <tr>
                <td class="layui-td-gray-2">{$vo.title}</td>
                <td>
                    <div class="layui-form-item">
                        {volist name="vo.options" id="item" key="k"}                        
                            <input type="checkbox" name="{$kv}" value="{$key}" title="{$item}" {in name="$key" value="$vo.value"}checked{/in}>
                        {/volist}
                    </div>
                    {notempty name="$vo.tips" }
                    <div class="layui-form-mid layui-text-em">{$vo.tips}</div>
                    {/notempty}
                </td>
            </tr>
        {/eq}
        {eq name="$vo.type" value="select"}
            <tr>
                <td class="layui-td-gray-2">{$vo.title}</td>
                <td>
                        <select name="{$kv}">
                            <option value="">请选择{$vo.title}</option>
                            {volist name="vo.options" id="item" key="k"}
                                <option value="{$key}" {eq name="$key" value="$vo.value"}selected{/eq}>{$item}</option>
                            {/volist}
                        </select>
                    {notempty name="$vo.tips" }
                    <div class="layui-form-mid layui-text-em">{$vo.tips}</div>
                    {/notempty}
                </td>
            </tr>
        {/eq}
        {eq name="$vo.type" value="image"}
            <tr>
                <td class="layui-td-gray-2">{$vo.title}</td>
                <td>
                    <div class="layui-upload" style="width: 240px;">
                        <div class="layui-upload-list" id="loginbgpic" style="width: 100%; height:100px; overflow: hidden;">
                            <img src='{notempty name="$vo.value"}{$vo.value}{/notempty}' style="max-width: 100%; width: 100%;" onerror="javascript:this.src='{__ASSETS__}/init/images/nonepic600x360.jpg';this.onerror=null;" />
                            <input type="hidden" name="{$kv}" {notempty name="$vo.value"} value="{$vo.value}"{/notempty}>
                        </div>
                        <button type="button" class="layui-btn layui-btn-normal" style="width: 100%;" id="uploadBtn">上传</button>                        
                    </div>
                    {notempty name="$vo.tips" }
                    <div class="layui-form-mid layui-text-em">{$vo.tips}</div>
                    {/notempty}
                </td>              
            </tr>
        {/eq}
        {/volist}
	</table>

	<div class="py-3">
        <input type="hidden" name="id" value="{$name}">
		<button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="webform">立即提交</button>
		<button type="reset" class="layui-btn layui-btn-primary">重置</button>
	</div>
</form>
{/block}
<!-- /主体 -->

<!-- 脚本 -->
{block name="script"}
<script>
	const moduleInit = ['tool'];
	function feiniaoInit() {
		var form = layui.form, tool = layui.tool, upload = layui.upload;
        //logo上传
		var uploadInst = upload.render({
			elem: '#uploadBtn',
			url: "{:url('api/upload')}",
			done: function (res) {
				if (res.code == 1) {
					layer.msg('上传失败');
				} else {
					layer.msg('上传成功');
					$('#loginbgpic input').attr('value', res.data.filepath);
					$('#loginbgpic img').attr('src', res.data.filepath);
				}
			}
		});
		//监听提交
		form.on('submit(webform)', function (data) {
			let callback = function (e) {
				layer.msg(e.msg);
				if (e.code == 0) {
					parent.layui.tool.close(1000);
				}
			}
			tool.post("{:url('plugin/config')}", data.field, callback);
			return false;
		});
	}
</script>
{/block}
<!-- /脚本 -->